/* -*-  Mode: C++; c-file-style: "gnu"; indent-tabs-mode:nil; -*- */
/*
 * Copyright (c) 2007 INESC Porto
 *
 * This program is free software; you can redistribute it and/or modify
 * it under the terms of the GNU General Public License version 2 as
 * published by the Free Software Foundation;
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with this program; if not, write to the Free Software
 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
 *
 * Author: Gustavo J. A. M. Carneiro  <gjc@inescporto.pt>
 */

#include "ns3/assert.h"

#include "texcp-header.h"
#include "ns3/log.h"

#define IPV4_ADDRESS_SIZE 4
#define TEXCP_PKT_HEADER_SIZE 8

namespace ns3 {
namespace texcp{
NS_LOG_COMPONENT_DEFINE("TexcpHeader");


NS_OBJECT_ENSURE_REGISTERED (TexcpHeader);

TexcpHeader::TexcpHeader ()
{
 m_path_utilization = 12;
 m_positive_feedback = 25;
 m_negative_feedback = 6;
 m_weight = 13;

}

TexcpHeader::~TexcpHeader ()
{}

TypeId
TexcpHeader::GetTypeId (void)
{
  static TypeId tid = TypeId ("ns3::texcp::TexcpHeader")
    .SetParent<Header> ()
    .AddConstructor<TexcpHeader> ()
    ;
  return tid;
}
TypeId
TexcpHeader::GetInstanceTypeId (void) const
{
  return GetTypeId ();
}

uint32_t 
TexcpHeader::GetSerializedSize (void) const
{
  return TEXCP_PKT_HEADER_SIZE;
}

void 
TexcpHeader::Print (std::ostream &os) const
{
 os << "PATH_UTILIZATION" << m_path_utilization;
}

void
TexcpHeader::Serialize (Buffer::Iterator start) const
{
  //Buffer::Iterator i = start;
  
  start.WriteHtonU16 (m_path_utilization);
  start.WriteHtonU16 (m_positive_feedback);
  start.WriteHtonU16 (m_negative_feedback);
  start.WriteHtonU16 (m_weight);
}

uint32_t
TexcpHeader::Deserialize (Buffer::Iterator start)
{
  //Buffer::Iterator i = start;
  m_path_utilization  = start.ReadNtohU16 ();
  m_positive_feedback  = start.ReadNtohU16 ();
  m_negative_feedback  = start.ReadNtohU16 ();
  m_weight  = start.ReadNtohU16 ();
  return GetSerializedSize ();
}


}} // namespace texcp,ns3

